home *** CD-ROM | disk | FTP | other *** search
/ Aminet 45 / Aminet 45 (2001)(GTI - Schatztruhe)[!][Oct 2001].iso / Aminet / game / role / ldmud-3.2-bin.lha / mud / mudlib / test_master.c < prev   
C/C++ Source or Header  |  2001-07-18  |  6KB  |  220 lines

  1. /* Test Master.c
  2.  *
  3.  * Minimal master.c to provide a very rudimentary test of the gamedriver.
  4.  * To perform the test, cd to the directory this file is in and give the
  5.  * command
  6.  *    driver -N -e -m. -Mtest_master.c -s-1 -sv-1 4242
  7.  * (this assumes that you called the gamedriver 'driver' and that it is
  8.  * in your searchpath).
  9.  * Once it's running, telnet to localhost, port 4242. You should be
  10.  * connected to the driver now and be able to enter commands.
  11.  * The command 'help' will list you the commands available.
  12.  *
  13.  * A second test consists of the simple command
  14.  *    driver --version
  15.  * The driver shall just print the version and exit immediately.
  16.  */
  17.  
  18. //---------------------------------------------------------------------------
  19. void inaugurate_master (int arg)
  20.  
  21. // Initialise the master object.
  22. // We have to set the uid hooks, otherwise we can't clone a login object.
  23.  
  24. {
  25.     set_driver_hook(2, unbound_lambda(({}), "uid"));
  26.     set_driver_hook(3, unbound_lambda(({}), "uid"));
  27.     set_driver_hook(10, "What?\n");
  28. }
  29.  
  30. //---------------------------------------------------------------------------
  31. string get_master_uid()
  32.  
  33. // Return the master uid.
  34. {
  35.     return " R O O T ";
  36. }
  37.  
  38. //---------------------------------------------------------------------------
  39. void flag (string arg)
  40.  
  41. // Evaluate an argument given as option '-f' to the driver.
  42.  
  43. {
  44.     if (arg == "test")
  45.     {
  46.         /* Insert your test code here */
  47.         return;
  48.     }
  49.  
  50.     if (arg == "gc")
  51.     {
  52.         garbage_collection();
  53.         return;
  54.     }
  55.  
  56.     if (arg == "dhry")
  57.     {
  58.         limited( (: load_object("dhrystone")->main(1000) :) );
  59.         shutdown();
  60.         return;
  61.     }
  62.  
  63.     if (arg == "shutdown")
  64.     {
  65.         shutdown();
  66.         return;
  67.     }
  68.     write ("master: Unknown flag "+arg+"\n");
  69. }
  70.  
  71. //---------------------------------------------------------------------------
  72. mixed prepare_destruct (object obj)
  73.  
  74. // Prepare the destruction of the object.
  75.  
  76. {
  77.     debug_message(sprintf("%O: prepare_destruct(%O)\n", this_object(), obj));
  78.     return 0;
  79. }
  80.  
  81. //---------------------------------------------------------------------------
  82. object connect ()
  83.  
  84. // Handle the request for a new connection.
  85. // We simply return a clone of ourself (we can't simply return this object
  86. // unfortunately), the gamedriver will then call logon() here.
  87.  
  88. {
  89.     object obj;
  90.     debug_message(sprintf("%O: connect()\n", this_object()));
  91.     obj = clone_object(object_name(this_object()));
  92.     return obj;
  93. }
  94.  
  95. //---------------------------------------------------------------------------
  96. static nomask mixed logon ()
  97.  
  98. // A connection was successfully bound to this object.
  99. // Print some status data and add the commands.
  100.  
  101. {
  102.     debug_message(sprintf("%O: logon()\n", this_object()));
  103.     write("\nLDMud " __VERSION__ "\n\n----------\n");
  104.     write(debug_info(4,0));
  105.     write("----------\n\n> ");
  106.     enable_commands();
  107.     add_action("f_help", "help");
  108.     add_action("f_shutdown", "shutdown");
  109.     add_action("f_echo", "echo");
  110.     add_action("f_flag", "flag");
  111.     add_action("f_gc", "gc");
  112.     add_action("f_upd", "upd");
  113.     add_action("f_quit", "quit");
  114.  
  115.     return 1; // To verify that the connection was accepted.
  116. }
  117.  
  118. //---------------------------------------------------------------------------
  119. int f_help (string arg)
  120.  
  121. // The 'help' command.
  122.  
  123. {
  124.     debug_message(sprintf("%O: f_help()\n", this_object()));
  125.     write(
  126. "  help     - Prints this message\n"
  127. "  shutdown - shuts down the driver\n"
  128. "  flag     - passes the argument to the flag() function\n"
  129. "  echo     - tests the input_to() function\n"
  130. "  gc       - performes a garbage collection\n"
  131. "  upd      - reloads the master object\n"
  132. "  quit     - terminates the connection, but leaves the driver running\n"
  133.     );
  134.     return 1;
  135. }
  136.  
  137. //---------------------------------------------------------------------------
  138. int f_flag (string arg)
  139.  
  140. // The 'flag' command.
  141.  
  142. {
  143.     debug_message(sprintf("%O: f_flag()\n", this_object()));
  144.     flag(arg);
  145.     return 1;
  146. }
  147.  
  148. //---------------------------------------------------------------------------
  149. int f_gc (string arg)
  150.  
  151. // The 'gc' command.
  152.  
  153. {
  154.     write("Requested a garbage collection.\n");
  155.     garbage_collection();
  156.     return 1;
  157. }
  158.  
  159. //---------------------------------------------------------------------------
  160. int f_echo (string arg)
  161.  
  162. // The 'echo' command.
  163.  
  164. {
  165.     debug_message(sprintf("%O: f_echo()\n", this_object()));
  166.     write("Please enter a line: ");
  167.     input_to("echoline");
  168.     return 1;
  169. }
  170.  
  171. //---------------------------------------------------------------------------
  172. void echoline (string text)
  173.  
  174. // The user entered some text. Echo it.
  175.  
  176. {
  177.     debug_message(sprintf("%O: echoline()\n", this_object()));
  178.     write("You entered: '"+text+"'\n");
  179. }
  180.  
  181. //---------------------------------------------------------------------------
  182. int f_shutdown (string arg)
  183.  
  184. // The 'shutdown' command.
  185.  
  186. {
  187.     debug_message(sprintf("%O: f_shutdown()\n", this_object()));
  188.     write("Shutting down.\n");
  189.     shutdown();
  190.     return 1;
  191. }
  192.  
  193. //---------------------------------------------------------------------------
  194. int f_upd (string arg)
  195.  
  196. // The 'upd' command.
  197.  
  198. {
  199.     debug_message(sprintf("%O: f_upd()\n", this_object()));
  200.     write("Removing old master...\n");
  201.     destruct(find_object(__MASTER_OBJECT__));
  202.     write("Loading master again...\n");
  203.     load_object(__MASTER_OBJECT__);
  204.     write("...done.\n");
  205.     return 1;
  206. }
  207.  
  208. //---------------------------------------------------------------------------
  209. int f_quit (string arg)
  210.  
  211. // The 'quit' command.
  212.  
  213. {
  214.     debug_message(sprintf("%O: f_quit()\n", this_object()));
  215.     write("Bye-bye.\n");
  216.     destruct(this_object());
  217.     return 1;
  218. }
  219.  
  220.